//
//  ForgetPasswordViewController.m
//  shopping
//
//  Created by 马田成 on 2017/9/12.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "ForgetPasswordViewController.h"
#import "SettingNewPasswordsViewController.h"
@interface ForgetPasswordViewController ()
@property (weak, nonatomic) IBOutlet UITextField *shoujiHanTF;
@property (weak, nonatomic) IBOutlet UITextField *yanzhengMa;
@property (weak, nonatomic) IBOutlet UITextField *MIMAASDFASDF;
@property (weak, nonatomic) IBOutlet UIButton *YZMBtn;

@end

@implementation ForgetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"忘记密码"];
     
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)sureClick:(UIButton *)sender {
    SettingNewPasswordsViewController *vc = [[SettingNewPasswordsViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (IBAction)yanzhengM:(UIButton *)sender {
    
    
//    NSMutableDictionary *productParamsss=[[NSMutableDictionary alloc]init];
//    //    NSString *token = [PublicFunction getConfigWithKey:@"token"];
//    
//    
//    [productParamsss setValue:self.shoujiHanTF.text forKey:@"phone"];
//    [productParamsss setValue:@"1" forKey:@"type"];
//    [[MNetworkHandler sharedInstance]conURL:adminLoginSendPhone networkType:NetWorkPOST params:productParamsss delegate:nil showHUD:NO successBlock:^(id returnData) {
//        
//        
//        if ([[returnData objectForKey:@"code"]intValue]==1) {
//            
//            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
//            
//            
//        }
//        
//        else {
//            
//            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
//            
//        }
//        
//    } failureBlock:^(NSError *error) {
//        
//        NSLog(@"%@",error);
//        
//        //        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
//        
//    }];
    
    
    NSMutableDictionary *productParamsss=[[NSMutableDictionary alloc]init];
    [productParamsss setValue:self.shoujiHanTF.text forKey:@"phone"];
    [productParamsss setValue:@"1" forKey:@"type"];
    
    [[MNetworkHandler sharedInstance]conURL:adminLoginSendPhone
                                networkType:NetWorkPOST
                                     params:productParamsss
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   
                                   if ([returnData[@"code"] intValue] == 1) {
                                       
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                       
                                       __block int timeout=60; //倒计时时间
                                       dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                                       dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
                                       dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
                                       
                                       dispatch_source_set_event_handler(_timer, ^{
                                           
                                           if(timeout<=0){ //倒计时结束，关闭
                                               
                                               dispatch_source_cancel(_timer);
                                               dispatch_async(dispatch_get_main_queue(), ^{
                                                   //设置界面的按钮显示 根据自己需求设置
                                                   [self.YZMBtn setTitle:@"发送验证码" forState:UIControlStateNormal];
                                                   
                                                   self.YZMBtn.userInteractionEnabled = YES;
                                               });
                                           }else{
                                               int seconds = timeout % 61;
                                               
                                               NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
                                               dispatch_async(dispatch_get_main_queue(), ^{
                                                   //设置界面的按钮显示 根据自己需求设置
                                                   //NSLog(@"____%@",strTime);
                                                   [UIView beginAnimations:nil context:nil];
                                                   [UIView setAnimationDuration:1];
                                                   [self.YZMBtn setTitle:[NSString stringWithFormat:@"%@秒",strTime] forState:UIControlStateNormal];
                                                   [UIView commitAnimations];
                                                   self.YZMBtn.userInteractionEnabled = NO;
                                               });
                                               timeout--;
                                           }
                                       });
                                       dispatch_resume(_timer);
                                   }else{
                                       
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                   }
                                   
                               }
                               failureBlock:^(NSError *error) {
                                   NSLog(@"%@",error);
                                  
                               }];

    
    
    
    
    
    
    

    
    
}
- (IBAction)sureButton:(UIButton *)sender {
    
    
    NSMutableDictionary *productParamsss=[[NSMutableDictionary alloc]init];
    //    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    
    
    [productParamsss setValue:self.shoujiHanTF.text forKey:@"userPhone"];
    [productParamsss setValue:self.yanzhengMa.text forKey:@"mobileCode"];
    [productParamsss setValue:self.MIMAASDFASDF.text forKey:@"loginPwd"];
    [[MNetworkHandler sharedInstance]conURL:adminLoginForgetpassword networkType:NetWorkPOST params:productParamsss delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
           
            [self.navigationController popViewControllerAnimated:YES];
            
            
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        //        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];

    
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
